<?php
declare (strict_types=1);

namespace app\middleware;

use app\utils\BaseVarDumper;
use think\facade\Log;

class Before
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {

        if (!empty($request->file())) {
            return $next($request);
        }
        $server = $request->server();
        $server_log = [
            'HTTP_COOKIE' => $server["HTTP_COOKIE"] ?? "",
            'HTTP_ACCEPT_LANGUAGE' => $server["HTTP_ACCEPT_LANGUAGE"] ?? "",
            'HTTP_ACCEPT_ENCODING' => $server["HTTP_ACCEPT_ENCODING"] ?? "",
            'HTTP_ACCEPT' => $server["HTTP_ACCEPT"] ?? "",
            'HTTP_USER_AGENT' => $server["HTTP_USER_AGENT"] ?? "",
            'HTTP_UPGRADE_INSECURE_REQUESTS' => $server["HTTP_UPGRADE_INSECURE_REQUESTS"] ?? "",
            'HTTP_CONNECTION' => $server["HTTP_CONNECTION"] ?? "",
            'HTTP_HOST' => $server["HTTP_HOST"] ?? "",
            "HTTP_REFERER"=>$server["HTTP_REFERER"] ?? "",
            "HTTP_CONTENT_TYPE"=>$server["HTTP_CONTENT_TYPE"] ?? ""
        ];
        Log::info("SERVER={server}", ["server" => BaseVarDumper::dumpAsString($server_log)]);
        if (!empty($request->post())) {
            Log::info("POST={post}", ["post" => BaseVarDumper::dumpAsString($request->post())]);
        }
        return $next($request);
    }
}
